﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using TV4Home.Server.TVEInteractionLibrary.Interfaces;
using System.ServiceModel;
using WebMediaPortal.Services;
using WebMediaPortal.Code;

namespace WebMediaPortal.Controllers
{

    [Authorize]
    public class TelevisionController : Controller
    {

        //
        // GET: /Television/
        public ActionResult Index()
        {
            return View();
        }

        public ActionResult TVGuide()
        {
            try
            {
                var channelList = WebServices.TVService.GetChannelsBasic(1);
                if (channelList != null)
                {
                    return View(channelList);
                }
            }
            catch (Exception ex)
            {
                Log.Error("Exception in Television.TVGuide", ex);
            }
            return View("Error");
        }

        public ActionResult WatchLiveTV(int channelId)
        {

            try
            {
                var channel = WebServices.TVService.GetChannelDetailedById(channelId);
                if (channel != null)
                {
                    return View(channel);
                }
            }
            catch (Exception ex)
            {
                Log.Error("Exception in Television.WatchLiveTV", ex);
            }
            return View("Error");
    
        }
        public ActionResult WatchRecording(int channelId)
        {
            try
            {
                //var channel = WebServices.TVService.GetChannelDetailedById(channelId);
                //if (channel != null)
                //{
                //    return View(channel);
                //}
            }
            catch (Exception ex)
            {
                Log.Error("Exception in Television.WatchRecording", ex);
            }
            return View("Error");
       
        }
        public ActionResult Recordings()
        {
            try
            {
                var recordings = WebServices.TVService.GetRecordings();
                if (recordings != null)
                {
                    return View(recordings);
                }
            }
            catch (Exception ex)
            {
                Log.Error("Exception in Television.Recordings", ex);
            }
            return View("Error");
        }




        public ActionResult Menu()
        {
            return PartialView();
        }        

        public ActionResult ProgramData(int channelId)
        {
            return PartialView(WebServices.TVService.GetProgramsDetailedForChannel(channelId, DateTime.Now, DateTime.Now.AddHours(4)));
        }
    }
}
